package com.lsu.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsu.app.bean.UserTaste;
import com.lsu.app.service.UserTasteService;
import com.lsu.app.mapper.UserTasteMapper;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @description 针对表【user_taste(用户兴趣标签)】的数据库操作Service实现
 * @Date 2023-10-23 19:28:40
 * @author hjj
 */
@Service
public class UserTasteServiceImpl extends ServiceImpl<UserTasteMapper, UserTaste> implements UserTasteService{
    private final UserTasteMapper mapper;

    public UserTasteServiceImpl(UserTasteMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Set<Integer> getKindIdsByTasteIds(Integer userId) {
        List<Integer> userTasteIds = mapper.getValuesByUserId(userId);
        if(userTasteIds.isEmpty()){
            return mapper.getAllKindIds();
        }
        Set<Integer> kindIds = new HashSet<>();
        for (Integer tasteId : userTasteIds) {
            kindIds.addAll(mapper.getKindsByTasteId(tasteId));
        }
        return kindIds;
    }
}




